package com.fishy.chat.model.entity;

import com.fishy.chat.enums.MessageType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 客户端请求
 *
 * @author sunn
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Message implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 消息类型
     */
    private MessageType type;
    /**
     * 内容
     */
    private String body;
    /**
     * 时间
     */
    private String time;

    public Message(MessageType type, String body) {
        this.type = type;
        this.body = body;
        setTime();
    }

    public void setTime() {
        this.time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm"));
    }

}
